var api = require('../../../utils/httpUtil.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    index: 1,
    topic: '',
    date: '2024-01-01',
    startTime: '08:00',
    endTime: '09:00',
    meetingRooms: [],
    selectedValue: '',
    selectedRoomId: 0,
    openId: app.globalData.openId
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    api.httpRequest(api.meetingRoomListAPI, {})
      .then(res => {
        if (res.code == 200) {
          this.setData({
            meetingRooms: res.data
          });
        } else {
          wx.showToast({
            title: res.msg,
            duration: 2000,
            mask: true,
            icon: 'none'
          })
        }
      })
      .catch(error => {
        wx.showToast({
          title: error.message,
          duration: 1000,
          mask: true,
          icon: 'none'
        })
      });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  topicInput: function (e) {
    this.setData({
      topic: e.detail.value
    })
  },
  dateChange(e) {
    this.setData({
      date: e.detail.value
    })
  },
  startChange(e) {
    this.setData({
      startTime: e.detail.value
    })
  },
  endChange(e) {
    this.setData({
      endTime: e.detail.value
    })
  },
  roomChange: function (e) {
    const index = e.detail.value;
    const selectedValue = this.data.meetingRooms[index];
    this.setData({
      selectedValue: selectedValue,
      selectedRoomId: index
    });
  },
  submit() {
    const stTime = this.data.date + " " + this.data.startTime + ":00";
    const edTime = this.data.date + " " + this.data.endTime + ":00";
    console.log(this.data.topic)
    api.httpRequest(api.meetingApplyAPI, {
        meetingId: this.data.selectedRoomId,
        topic: this.data.topic,
        applyStartTime: stTime,
        applyEndTime: edTime,
        openId: this.data.openId
      })
      .then(res => {
        wx.showToast({
          title: res.msg,
          duration: 2000,
          mask: true,
          icon: 'none'
        })
      })
      .catch(error => {
        wx.showToast({
          title: error.message,
          duration: 1000,
          mask: true,
          icon: 'none'
        })
      });
  }
})